package com.ahaoyou.blockingqueue;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author LH
 * @create 2022/4/13 10:51
 */
public class QueueTest {
    public static void main(String[] args) {
        LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
        new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                try {
                    queue.put(i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(() -> {
            try {
                for (; ; ) {
                    Integer take = queue.take();
                    System.out.println(Thread.currentThread().getName() + "===========" + take);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "consumer01").start();

        new Thread(() -> {
            try {
                for (; ; ) {
                    Integer take = queue.take();
                    System.out.println(Thread.currentThread().getName() + "===========" + take);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "consumer02").start();
    }
}
